package vip.rssc.mybatisplus.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import vip.rssc.mybatisplus.service.TestUserService;
import vip.rssc.mybatisplus.entity.TestUser;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>Description: [TestUserPlusController]</p >
 * Created on 2020年10月25日
 *
 * @author <a href="1014376159@qq.com">CJ</a>
 * @version 1.0
 * Copyright (c) 2020 cj
 */


@RestController("mybatisPlusTestUserController")
@RequestMapping("mybatis-plus/user")
@Slf4j
public class TestUserController {

    @Resource(name = "mybatisPlusTestUserServiceImpl")
    private TestUserService testUserService;

    /**
     * localhost:8080/mybatis-plus/user/save
     * {"name":"cj","age":4,"birthday":"2017-05-13","remark":""}
     * @param testUser
     */


    @PostMapping("save")
    public void save(@RequestBody TestUser testUser) {
        testUserService.save(testUser);
    }

    /**
     * localhost:8080/mybatis-plus/user/update
     * {"name":"cj","age":2,"birthday":"2017-05-13","remark":""}
     * @param testUser
     */


    @PostMapping("update")
    public void updateById(@RequestBody TestUser testUser) {
        testUserService.updateById(testUser);
    }

    /**
     * localhost:8080/mybatis-plus/user/get/1
     * @param id
     * @return
     */


    @GetMapping("get/{id}")
    public TestUser selectById(@PathVariable("id") Long id) {
        return testUserService.getById(id);
    }

    /**
     * localhost:8080/mybatis-plus/user/select
     * @return
     */


    @GetMapping("select")
    public List<TestUser> selectList() {
        return testUserService.list();
    }

    /**
     * localhost:8080/mybatis-plus/user/delete/1
     * @param id
     */


    @PostMapping("delete/{id}")
    public void deleteById(@PathVariable("id") Long id) {
        testUserService.removeById(id);
    }

    /**
     * localhost:8080/mybatis-plus/user/page/1/10
     * @param pageNo
     * @param pageSize
     */


    @GetMapping("page/{pageNo}/{pageSize}")
    public Page<TestUser> pageList(@PathVariable("pageNo") Long pageNo, @PathVariable("pageSize") Long pageSize) {
        return testUserService.pageList(pageNo, pageSize);
    }

}
